package cn.monkey.family.data.uc.org.dept;

import cn.monkey.family.data.EntityMapper;
import cn.monkey.family.data.TreeMapper;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.Collection;

@Mapper(unmappedTargetPolicy = org.mapstruct.ReportingPolicy.IGNORE)
public abstract class DepartmentMapper extends EntityMapper<Department, Department, DepartmentVo>
        implements TreeMapper<String, Department, DepartmentVo> {
    @Override
    @Mapping(target = "creator", source = "creatorId", qualifiedByName = "getUserIdAndNamePairFromId")
    @Mapping(target = "updater", source = "updaterId", qualifiedByName = "getUserIdAndNamePairFromId")
    public abstract DepartmentVo toVo(Department department);

    @Override
    public abstract Department toEntity(Department department);

    public Collection<DepartmentVo> toTree(Collection<Department> collection, int maxDeep) {
        return TreeMapper.super.toTree(collection, this::toVo, Department::getId, Department::getParentId, DepartmentVo::setChild, maxDeep);
    }

    public Collection<DepartmentVo> toTree(Collection<Department> collection) {
        return this.toTree(collection, 10);
    }
}
